#include "StdAfx.h"
#include "ConsumerLoanModel.h"


ConsumerLoanModel::ConsumerLoanModel(void)
{
	m_id = -1;
	m_consumerID = -1;
	m_loanType = -1;
	m_loanBank = "";
	m_loanSum = _T("");
	m_loanTime = -1;
	m_montyPay = _T("");
	m_dueSum = _T("");
}

ConsumerLoanModel::~ConsumerLoanModel(void)
{
}

void ConsumerLoanModel::parseFromJson(Json::Value& jsonData)
{
	if (!jsonData["loanType"].isNull()) 
	{
		this->m_loanType = jsonData["loanType"].asInt();
	}	
	if (!jsonData["loanTime"].isNull()) 
	{
		this->m_loanTime = jsonData["loanTime"].asInt();
	}
	
	CUtils::getJsonStringField(jsonData, "loanBank", m_loanBank);
	CUtils::getJsonStringField(jsonData, "loanMoney", m_loanSum);
	CUtils::getJsonStringField(jsonData, "monthPay", m_montyPay);
	CUtils::getJsonStringField(jsonData, "jieqianMoney", m_dueSum);
}

void ConsumerLoanModel::toJson(Json::Value& jsonData)
{
	if (this->m_loanType >= 0) 
	{
		jsonData["loanType"] = this->m_loanType;
	}
	if (this->m_loanBank >= 0) 
	{
		jsonData["loanBank"] = this->m_loanBank.GetBuffer();
	}
	if (this->m_loanSum.GetLength() > 0) 
	{
		jsonData["loanMoney"] = this->m_loanSum.GetBuffer();
	}
	if (this->m_loanTime >= 0) 
	{
		jsonData["loanTime"] = this->m_loanTime;
	}
	if (this->m_montyPay.GetLength() > 0) 
	{
		jsonData["monthPay"] = this->m_montyPay.GetBuffer();
	}
	if (this->m_dueSum.GetLength() > 0) 
	{
		jsonData["jieqianMoney"] = this->m_dueSum.GetBuffer();
	}
}
